import alert from './Alert.vue'
let instance;
const plugin = {
  install (vue) {
    let Alerting = vue.extend(alert);
    if (!instance) {
      instance = new Alerting({
        el: document.createElement('div')
      })
      document.body.appendChild(instance.$el);
    }
    const alerting = {
      show (options = {}) {
        if (typeof options === 'string') {
          instance.message = options;
          instance.flag = false;
        }
        else if (typeof options === 'object') {
          instance.flag = options['flag'];
          instance.message = options['text'];
        }
        instance.show();
      }
    }
    vue.$xalert = alerting;
    vue.mixin({
      created: function () {
        this.$xalert = vue.$xalert;
      }
    })
  }
}
export default plugin
export const install = plugin.install